package com.gitee.huanminabc.dynamicdb.core;

import com.gitee.huanminabc.dynamicdb.common.DynamicDbException;

/**
 * @author huanmin
 * @date 2024/11/22
 */
public class DbKeysManage {


    /**
     * 切换数据源
     */
    public static void switchDbKey(String dbKey) {
        dbKey = TenantKey.getKeyDb(dbKey);//多租户
        DBContext.dbKeys.set(dbKey);
    }


    /**
     * 获取当前数据源的key
     */
    public static String currentDbKey() {
        String dbKey = DBContext.dbKeys.get();
        if (dbKey == null) {
            throw new DynamicDbException("当前线程没有指定数据源");
        }
        dbKey=TenantKey.getKeyDb(dbKey);//多租户
        return dbKey;
    }
}
